package entities;

import java.io.Serializable;

import javax.persistence.*;

import ejb.dto.ExcursionDTO;

import java.util.List;


/**
 * The persistent class for the excursions database table.
 * 
 */
@Entity
@Table(name="excursions")
@NamedQueries({
	@NamedQuery(name="Excursion.findAll", query="SELECT e FROM Excursion e"),
	@NamedQuery(name="Excursion.findByLocation", query="SELECT e FROM Excursion e WHERE e.location=:l"),
	@NamedQuery(name="Excursion.findByLocationAndPeriod", query="SELECT e FROM Excursion e WHERE e.location=:l")
})
public class Excursion implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	private int id;

	private String description;

	@ManyToOne
	private Location location;
	
	/**
	 * bi-directional many-to-many association to Package
	 */
	@ManyToMany(mappedBy="excursions")
	private List<Package> packages;

	private String name;

	private float price;

	/**
	 * bi-directional many-to-one association to ExcursionAvailability
	 */
	@OneToMany(mappedBy="excursion")
	private List<ExcursionAvailability> excursionAvailabilities;

	
	//CONSTRUCTORS
	public Excursion() {
	}
	
	public Excursion(ExcursionDTO excursion, Location location){
		this.id = excursion.getId();
		this.description = excursion.getDescription();
		this.name = excursion.getName();
		this.price = excursion.getPrice();
		this.location = location;
	}
	
	
	
	//GETTER AND SETTER
	public Location getLocation() {
		return location;
	}

	public void setLocation(Location location) {
		this.location = location;
	}


	public int getId() {
		return this.id;
	}

	public void setId(int id) {
		this.id = id;
	}

	public String getDescription() {
		return this.description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public float getPrice() {
		return this.price;
	}

	public void setPrice(float price) {
		this.price = price;
	}

	public List<ExcursionAvailability> getExcursionAvailabilities() {
		return this.excursionAvailabilities;
	}

	public void setExcursionAvailabilities(List<ExcursionAvailability> excursionAvailabilities) {
		this.excursionAvailabilities = excursionAvailabilities;
	}

	
	public List<Package> getPackages() {
		return packages;
	}

	public void setPackages(List<Package> packages) {
		this.packages = packages;
	}
	
	//METHODS
	
	/**
	 * add new ExcursionAvailability to list
	 * @param excursionAvailability
	 * @return list of ExcursionAvailability
	 */
	public ExcursionAvailability addExcursionAvailability(ExcursionAvailability excursionAvailability) {
		getExcursionAvailabilities().add(excursionAvailability);
		excursionAvailability.setExcursion(this);

		return excursionAvailability;
	}

	/**
	 * remove one ExcursionAvailability from list
	 * @param excursionAvailability
	 * @return list of ExcursionAvailability
	 */
	public ExcursionAvailability removeExcursionAvailability(ExcursionAvailability excursionAvailability) {
		getExcursionAvailabilities().remove(excursionAvailability);
		excursionAvailability.setExcursion(null);

		return excursionAvailability;
	}

}